import PageProgress from './PageProgress.js'
import Book from './Book.js'
export default class Lesson {
  constructor(options = {}) {
    this.name = options.name || ''
    this.books = []
  }
  addBook(book) {
    this.books.push(book)
    return this
  }
  toJSON() {
    return {
      name: this.name,
      books: this.books.map((res) => res.toJSON())
    }
  }
  fromJSON(json) {
    this.name = json.name
    this.books.length = 0
    json.books.forEach((res) => {
      this.books.push(new Book().fromJSON(res))
    })
    return this
  }
}
